//
//  SMainViewController.swift
//  SWeiboBoom
//
//  Created by Angus.丶 ShangYang on 16/8/9.
//  Copyright © 2016年 Angus_Shyang. All rights reserved.
//

import UIKit

class SMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //实例化自定义tabBar
        let tabBar = STabBar()
        //设置代理
        tabBar.sDelegate = self
        //只读属性
        //通过kvc给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        //首页
        addChildViewController(SHomeViewController(), imgName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(SMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(SDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(SProfileViewController(), imgName: "tabbar_profile", title: "我")
    }
    
    /*
     添加子控制器
     - parameter vc:控制器
     - parameter imgName:图片名称
     - parameter title: title
     */
    func addChildViewController(vc: UIViewController,imgName:String,title:String) {
        //设置title
        vc.title = title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        //AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController:vc))
    }
}

extension SMainViewController:STabBarDelegate{
    func tabBarButtonClick() {
        print("撰写按钮被点击")
    }
}







